/*
 * @Author: sean_kei@163.com
 * @Date: 2021-06-08 15:07:38
 * @LastEditors: sean_kei@163.com
 * @LastEditTime: 2022-08-04 13:42:25
 */
package com.wxhandle.cleandemo.core.domain.identity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
@Data
@Entity
@IdClass(ClaimKey.class)
@Table(name = "SysClaim", uniqueConstraints = @UniqueConstraint(columnNames= {"id", "service_id"}))
public class SysClaim implements Serializable {

    @Id
    @Column(name = "id", length = 50, nullable = false)
    private String id;

    @Id
    @Column(name = "service_id", length = 50, nullable = false)
    private String serviceId;

    /**
     * 声明描述
     */
    @Column(name = "description", length = 100, nullable = false)
    private String description;

    /**
     * Action或Url地址
     */
    @Column(name = "action", length = 100, nullable = false)
    private String action;

    /**
     * 顺序号
     */
    @Column(name = "sorting", nullable = false)
    private int sorting;


    @ManyToOne
    @JoinColumn(name = "service_id",insertable=false, updatable=false)
    private SysService service;

    @ManyToOne
    @JoinColumn(name = "parent_id", referencedColumnName = "id",insertable=false, updatable=false)
    @JoinColumn(name = "service_id", referencedColumnName = "service_id",insertable=false, updatable=false)
    private SysClaim parent;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
    private List<SysClaim> children;

    public static SysClaim of(String id,String desc, String action,int sorting){
        return new SysClaim(id, "",desc,action,sorting,null,null,null);
    }

}
